import {z} from 'zod';

//zod可以定义复杂的嵌套结构对象，数组，联合类型

const userSchema = z.object({
    name:z.string(),
    age:z.number(),
    email:z.string().email(),
})

let user = {
    name:'张三',
    age:18,
    email:'2646403766@qq.com'
}

try {
    const result = userSchema.parse(user);
    console.log(result)
}catch (err){
    console.log(err)
}

// 错误的
let user2 = {
    name:1,
    age:'a',
    email:'2646403766@qq.com'
}
try {
    const result = userSchema.parse(user2);
    console.log(result)
}catch (err){
    console.log(err)
}